import { panel } from "./panel/panel";
import PanelDefine from "./PanelDefine";

export default class PanelManager {
    public static getPanel(panelID: number) {
        switch (panelID) {
            case PanelDefine.PANEL_ID_1001:
                return ['package_loading', 'panel_loading'];   //包名、组件名                
            case PanelDefine.PANEL_ID_1002:
                return ['package_hall', 'panel_hall'];         //包名、组件名               
        }
    }

    public static loadPanel(panelID: number, server_data: any = null) {
        let panel_name: any = PanelManager.getPanel(panelID);
        cc.assetManager.loadBundle(panel_name[0], (err, bundle) => {
            if (!err) {
                console.log('bundle:', bundle);
                //先加载包
                fgui.UIPackage.loadPackage(bundle, panel_name[0], (error: any, pkg: fgui.UIPackage) => {
                    if (error) {
                        console.log('err', error);
                    }
                    else {
                        console.log('pkg', pkg);

                        let node: fgui.GComponent = new fgui.GComponent();
                        node.name = panel_name[1] as string;
                        node.node.name = panel_name[1] as string;
                        node.node.addComponent(panel_name[1]);
                        let la = node.node.getComponent(panel_name[1]) as any;
                        let aa = la.zindex
                        la.server_data = server_data;
                        la._pview = node;
                        let layer: fgui.GComponent = fgui.GRoot.inst.getChild(aa) as fgui.GComponent;
                        layer.addChild(node);

                        //fgui.GRoot.inst.node.getChildByName(aa).children[0].children[0].addChild(node);

                    }
                });

            }
        });

    }
}